package liecai_class.day07;

import java.util.concurrent.*;

/**
 * 线程池 - 快捷创建线程池 - Executors
 */
public class Demo04 {
    public static void main(String[] args) {
        /**
         * 创建一个可以随任务创建线程没有容量限制的线程池
         * 适合于大量短时任务的场景
         * new ThreadPoolExecutor(0, Integer.MAX_VALUE,
         *                        60L, TimeUnit.SECONDS,
         *                        new SynchronousQueue<Runnable>());
         */
        //ExecutorService pool = Executors.newCachedThreadPool();


        /**
         *  创建一个具有固定线程数的线程池
         *  提供了一个无界队列来存放任务
         *  new ThreadPoolExecutor(nThreads, nThreads,
         *                        0L, TimeUnit.MILLISECONDS,
         *                        new LinkedBlockingQueue<Runnable>());
         */
        //ExecutorService pool = Executors.newFixedThreadPool(5);

        /**
         * 创建一个只有一个线程的线程池
         * 提供了一个无界队列来存放任务
         * new ThreadPoolExecutor(1, 1,
         *                       0L, TimeUnit.MILLISECONDS,
         *                       new LinkedBlockingQueue<Runnable>())
         */
        ExecutorService pool = Executors.newSingleThreadExecutor();

    }
}
